package com.pub.database;

import java.util.*;

import javax.servlet.jsp.*;

import bsh.*;
import com.pub.database.access.*;
import com.pub.database.mysql.MysqlFunction;
import com.pub.database.oracle.*;
import com.pub.database.sqlite.*;
import com.pub.tools.*;

public class DataView {
    private final int INT_FIELD_TITLE = 0;
    private final int INT_FIELD_KIND = 1;
    private final int INT_FIELD_PROPERTY = 2;
    private final int INT_FIELD_HTML = 3;
    private final int INT_FIELD_VALUE = 4;
    private final int INT_LINK_URI = 5;
    private final int INT_PARAM_START_INDEX = 6;

    //這兒會用public 是希望外部程設在設定Hashtable時，所用的key name是來抓這兒的值去用，而不要直接寫在code
    public final String STR_FIELD_TITLE = "FIELD_TITLE";
    public final String STR_FIELD_KIND = "FIELD_KIND";
    public final String STR_FIELD_PROPERTY = "FIELD_PROPERTY";
    public final String STR_FIELD_HTML = "FIELD_HTML";
    public final String STR_FIELD_VALUE = "FIELD_VALUE";
    public final String STR_LINK_URI = "LINK_URI";
    public final String STR_LINK_PARAM = "PARAM";
    public final String STR_FIELD_NAME = "FIELD_NAME";
    public final String STR_FIELD_SUB_SQL = "FIELD_SUB_SQL";
    //public final String STR_END_TD_PROPERTY = "END_TD_PROPERTY";
    //public final String STR_TITLE_END_TD_PROPERTY = "END_TITLE_TD_PROPERTY";
    public final String STR_FIELD_APPEND_ROW_HTML = "FIELD_APPEND_ROW_HTML";
    public final String STR_FIELD_LINE_FEED = "FIELD_LINE_FEED";

    private final String gstrReplaceRowSN = "%sn%";
    //private final String gstrDynamicCode = "$";
    //private final String gstrArrayVaribeMark = "{";

    private ArrayList<Hashtable<String,Object>> galtColRelation = null;
    private Hashtable<String,Hashtable<String,Object>> ghtRowData = null;
    private ArrayList<String> galtColData = null;
    //private boolean gblnDebug = false;
    //private StringBuffer gstbAppendRowScript = new StringBuffer();

    private String gstrDBAlias = null;
    private boolean gblnDBDebug = false;
    private String gstrSourceCharset = null;
    private String gstrTargetCharset = null;
    private QueryBean gqbnDAO = null;
    private boolean gqblnOutQueryBean = false;
    //private boolean gblnNeedQuery = true;

    public DataView(String pstrDBAlias, boolean pblnDBDebug,
                    String pstrSourceCharset, String pstrTargetCharset) {
        gstrDBAlias = pstrDBAlias;
        gblnDBDebug = pblnDBDebug;
        gstrSourceCharset = pstrSourceCharset;
        gstrTargetCharset = pstrTargetCharset;
        gqbnDAO = new QueryBean(gstrDBAlias, gblnDBDebug,
                                gstrSourceCharset, gstrTargetCharset);
        gqblnOutQueryBean = false;
        //gblnNeedQuery = true;
    }

    public DataView(QueryBean pqbnDAO) {
        gqbnDAO = pqbnDAO;
        gqblnOutQueryBean = true;
        //gblnNeedQuery = true;
    }

    public DataView(Hashtable<String,Hashtable<String,Object>> phtRowData, ArrayList<Hashtable<String,Object>> paltColData) {
        ghtRowData = phtRowData;
        //galtColData = paltColData;
        //gblnNeedQuery = false;
    }

    /**
     * closeQueryBean
     *
     * @throws Exception
     */
    private void closeQueryBean() throws Exception {
        if (!gqblnOutQueryBean) {
            try {
                if (gqbnDAO != null) {
                    gqbnDAO.close();
                }
            } catch (Exception se) {
                throw new Exception(
                        "close QueryBean Exception in DataView.closeQueryBean()");
            }
            gqbnDAO = null;
        }
    }

    public String getOutputDataView(DataViewForm actionForm) throws Exception {
        DataViewForm dataViewForm = (DataViewForm) actionForm;

        StringBuffer stbSQL = new StringBuffer();
        StringBuffer lstbHtmlCode = new StringBuffer();

        int intNowPage = dataViewForm.getNowPageNum();
        long lngStartRow = 0;
        long lngEndRow = 0;

        try {
            if ((dataViewForm.getTablesList() == null ||
                 dataViewForm.getTablesList().trim().equals("")) &&
                (dataViewForm.getSQL() == null &&
                 dataViewForm.getSQL().trim().equals(""))) { //若沒有傳入SQL
                if (gblnDBDebug) {
                    System.out.println("sql is null then return");
                }
                return null;
            }

            //如果nowPage=0/*或SQL 有變動*/
            if ( /*!strSQL.equals(dataViewForm.getSQL()) ||*/
                            dataViewForm.getNowPageNum() == 0) {
                dataViewForm.setNowPageNum(1);
                intNowPage = 1;
            }

            //讀取資料總筆數
            dataViewForm.setTotalDataSize(PublicFunction.String_to_int(gqbnDAO.
                    readSingleValueData(combindCountSQL(dataViewForm))));

            if (dataViewForm.getPageRowCount() == 0) {
                dataViewForm.setPageRowCount(dataViewForm.getTotalDataSize());
            }

            //設定要顯示的列數範圍
            lngStartRow = (intNowPage - 1) * dataViewForm.getPageRowCount();
            lngEndRow = intNowPage * dataViewForm.getPageRowCount();

            if (dataViewForm.getSQL() == null ||
                dataViewForm.getSQL().trim().equals("")) {
                if (dataViewForm.getFieldsList() == null ||
                    dataViewForm.getFieldsList().trim().equals("")) {
                    setAppendRowsField(dataViewForm.getColRelationUseArrayList()); //因dataview會自己多一個欄位來記錄每一筆的狀態，所以要多設定一組欄位設定
                    dataViewForm.setFieldsList(combindSelectFields(dataViewForm.
                            getColRelationUseArrayList()));
                }
                dataViewForm.setSQL(combindSQL(dataViewForm.getFieldsList(),
                                               dataViewForm.getTablesList(),
                                               dataViewForm.getSQLCondition(),
                                               dataViewForm.getOrderByFields(),
                                               dataViewForm.getOrderBySeq(),
                                               dataViewForm.getGroupBy(),
                                               dataViewForm.getHaving()));
            }

            //組合分頁SQL
            if (gqbnDAO.getDBType().toUpperCase().equals("ORACLE")) {
                stbSQL.append(OracleFunction.incPageSizeSQL(dataViewForm.getSQL(),
                        lngStartRow, lngEndRow));
            } else if (gqbnDAO.getDBType().toUpperCase().equals("ACCESS")) {
                stbSQL.append(AccessFunction.incPageSizeSQL(dataViewForm.
                        getFieldsList(),
                        dataViewForm.getTablesList(),
                        dataViewForm.getSQLCondition(),
                        dataViewForm.getGroupBy(),
                        dataViewForm.getHaving(),
                        dataViewForm.getOrderByFields(),
                        dataViewForm.getOrderBySeq(),
                        dataViewForm.getPageRowCount() * intNowPage,
                        dataViewForm.getPageRowCount()));
            } else if (gqbnDAO.getDBType().toUpperCase().equals("SQLITE")) {
            	stbSQL.append(SqliteFunction.incPageSizeSQL(dataViewForm.getSQL(),
                        lngStartRow, dataViewForm.getPageRowCount()));
            } else if (gqbnDAO.getDBType().toUpperCase().equals("MYSQL")) {
            	stbSQL.append(MysqlFunction.incPageSizeSQL(dataViewForm.getSQL(),
                        lngStartRow, dataViewForm.getPageRowCount()));
            }
            else{
                throw new Exception("Not implement " + gqbnDAO.getDBType() + "Function.incPageSizeSQL in DataView.getOutputDataView");
            }


            //以arraylist 型態取出resultset and colnum
            ghtRowData = gqbnDAO.hashtableSQL(stbSQL.toString());

            //取得query順序的欄位名稱
            galtColData = gqbnDAO.getArlcolumnLabel();

            //後面不會再用到QueryBean 故提早close，但為避免在這行之前的code 有exception 在finally仍會再closeQueryBean
            closeQueryBean();

            //若沒有 rowdata 且 dataViewForm.getShowHeaderWhenNoData() 為 false 則以下皆不跑
            if ((ghtRowData == null || ghtRowData.size() == 0) &&
                !dataViewForm.getShowHeaderWhenNoData()) {
                return null;
            }

            galtColRelation = (dataViewForm.getColRelation() != null ?
                               transferStringArrayColRelationToArrayList(
                                       dataViewForm.getColRelation(),
                                       galtColData) :
                               dataViewForm.getColRelationUseArrayList());

            /* 這段是產生 Excel 的 code
                         if (dataViewForm.getDataViewAction() != null &&
                dataViewForm.getDataViewAction().trim().equals("excel")) {
                dataViewForm.setdvSQLCondition(dataViewForm.
                                               getdvSQLCondition() + " and " +
                                               gstrColRelation[
                                               Integer.parseInt(dataViewForm.
                        getFilterCol())][
                                               INT_FIELD_DATA] + "=" +
                                               (gstrColRelation[
                                                Integer.parseInt(dataViewForm.
                        getFilterCol())][
                                                INT_FIELD_TYPE].toLowerCase().
                                                equals("text") ?
                                                "'" : "") +
                                               dataViewForm.getFilterValue() +
                                               (
                        gstrColRelation[Integer.parseInt(dataViewForm.
                        getFilterCol())][INT_FIELD_TYPE].toLowerCase().
                        equals("text") ? "'" : ""));
                         }*/


            //記錄欄數
            for (int i = 0; i < galtColRelation.size(); i++) {
                if (!((Hashtable<String,Object>) galtColRelation.get(i)).get(this.
                        STR_FIELD_TITLE).toString().equals(
                                "N") &&
                    !((Hashtable<String,Object>) galtColRelation.get(i)).get(this.
                        STR_FIELD_TITLE).toString().equals(
                                "HIDDEN")) { //判斷該欄是否要顯示
                    dataViewForm.setColumnSize(dataViewForm.getColumnSize() + 1);
                }
            }

            //記錄此次資料總筆數(因最後一頁的筆數不固定，不可用pageRowCount代替)
            dataViewForm.setReadDataSize((ghtRowData == null ? 0 :
                                          ghtRowData.size()));
            //更新目前頁數
            dataViewForm.setNowPageNum(intNowPage);

            if (dataViewForm.getPageScript() != null) { //輸出指定script
                lstbHtmlCode.append(dataViewForm.getPageScript());
            }

            //分析PageAction所要用的值
            String strPageAction = (dataViewForm.getPageActionURI().indexOf("?") ==
                                    -1 ?
                                    dataViewForm.getPageActionURI() :
                                    dataViewForm.getPageActionURI().substring(0,
                    dataViewForm.getPageActionURI().indexOf("?")));

            String strParams[] = dataViewForm.getPageActionURI().substring(
                    dataViewForm.getPageActionURI().
                    indexOf("?") + 1).split("&");

            if (dataViewForm.getPageActionURI().indexOf("?") == -1) {
                strParams[0] = "noparamters";

            }

            lstbHtmlCode.append("<form action='" + strPageAction +
                                "' method='" + dataViewForm.getSubmitMethod() +
                                "' name='" + dataViewForm.getHtmlFormName() +
                                "'>\r\n");

            if (dataViewForm.getHeaderFix()) {
                lstbHtmlCode.append("<table " + dataViewForm.getTableHtml() +
                                    " >\r\n");
            } else {
                lstbHtmlCode.append("<table id='" + dataViewForm.getTableId() +
                                    "' " + dataViewForm.getTableHtml() +
                                    " >\r\n");
            }

            //Title 部份要用<thead>包起來
            lstbHtmlCode.append("<thead id='");
            lstbHtmlCode.append(dataViewForm.getTableId());
            lstbHtmlCode.append("Head'>");

            //印出頁面上下頁按鈕及相關控制
            if (dataViewForm.getPageBtnOnTop()) {
                lstbHtmlCode.append(outputPageControl(dataViewForm,
                        galtColData));
            }

            //印出標題欄位
            lstbHtmlCode.append(outputDataTitle(dataViewForm.getOrderEnable(),
                                                dataViewForm.getHtmlFormName(),
                                                dataViewForm.getPropertiesFile(),
                                                dataViewForm.getTableHeaderHtml(),
                                                galtColData));

            lstbHtmlCode.append("</thead>");

            if (dataViewForm.getHeaderFix()) {
                lstbHtmlCode.append("</table>\r\n");
                lstbHtmlCode.append("<div id='div" + dataViewForm.getTableId() +
                                    "' style='overflow:auto;height:" +
                                    dataViewForm.getTableDataHeight() +
                                    "'>\r\n");
                lstbHtmlCode.append("<table id='" + dataViewForm.getTableId() +
                                    "' " + dataViewForm.getTableHtml() +
                                    " >\r\n");
            }

            //若顯示列數範圍大於arraylist size
            if (ghtRowData != null && lngEndRow > (ghtRowData.size() - 1)) {
                lngEndRow = ghtRowData.size() - 1;
            }

            //if (dataViewForm.getAddNewShow()) { //暫時保留if的code是要加入tbody向下相容若有問題時，則要恢復if
            //Data 部份要用<tbody>包起來
            lstbHtmlCode.append("<tbody id='");
            lstbHtmlCode.append(dataViewForm.getTableId());
            lstbHtmlCode.append("Body'>");
            //}
            if (ghtRowData != null && ghtRowData.size() > 0) { //輸出資料
                lstbHtmlCode.append(outputRowData(dataViewForm.
                                                  getTableDataTrHtml()));
            }
            //if (dataViewForm.getAddNewShow()) {
            lstbHtmlCode.append("</tbody>");
            //}

            //要用<tfoot>包起來
            lstbHtmlCode.append("<tfoot id='");
            lstbHtmlCode.append(dataViewForm.getTableId());
            lstbHtmlCode.append("Foot'>");

            //印出頁面上下頁按鈕及相關控制
            if (dataViewForm.getPageBtnOnButtom()) {
                lstbHtmlCode.append(outputPageControl(dataViewForm,
                        galtColData));
            }

            lstbHtmlCode.append("</tfoot>");

            lstbHtmlCode.append(outputFormHiddenFields(strParams, dataViewForm)); //輸出Hidden欄位

            lstbHtmlCode.append("</table>\r\n");

            if (dataViewForm.getHeaderFix()) {
                lstbHtmlCode.append("</div>");
            }
            lstbHtmlCode.append("</form>\r\n");

            //若有打開新增模式
            if (dataViewForm.getAddNewShow()) {
                //dataViewForm.setAppendRowScript();
                lstbHtmlCode.append(this.getAppendRowHtml(dataViewForm,
                        this.galtColRelation));
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new Exception(e);
        } finally {
            dataViewForm = null;
            closeQueryBean();
            if (this.galtColRelation != null) {
                this.galtColRelation.clear();
                this.galtColRelation = null;
            }
            if (this.ghtRowData != null) {
                this.ghtRowData.clear();
                this.ghtRowData = null;
            }
            if (this.galtColData != null) {
                this.galtColData.clear();
                this.galtColData = null;
            }
        }

        return lstbHtmlCode.toString();
    }

    /**
     * setAppendRowsField
     *
     * @param paltColRelation ArrayList
     */
    @SuppressWarnings("unchecked")
	private void setAppendRowsField(ArrayList paltColRelation) throws Exception {
        Hashtable<String,String> lhtColRelationDetail = new Hashtable<String,String>();

        try {
            lhtColRelationDetail.put(this.STR_FIELD_NAME, "DATAVIEW_ROW_STATUS");
            lhtColRelationDetail.put(this.STR_FIELD_SUB_SQL, "''");
            lhtColRelationDetail.put(this.STR_FIELD_TITLE, "HIDDEN");
            lhtColRelationDetail.put(this.STR_FIELD_KIND, "INPUT");
            lhtColRelationDetail.put(this.STR_FIELD_PROPERTY,
                                     "WIDTH='10%' align='center'");
            lhtColRelationDetail.put(this.STR_FIELD_HTML,
                                     "<input type='hidden' name='dataview_row_status' value=");
            lhtColRelationDetail.put(this.STR_FIELD_APPEND_ROW_HTML,
                                     "<input type='hidden' name='dataview_row_status' value='I'/>");
            lhtColRelationDetail.put(this.STR_FIELD_VALUE,
                                     "DATAVIEW_ROW_STATUS");

            paltColRelation.add(new Hashtable<String,String>(lhtColRelationDetail));
            lhtColRelationDetail.clear();
        } catch (Exception e) {
            if (this.gblnDBDebug) {
                e.printStackTrace();
            }
            throw new Exception(e);
        } finally {
            if (lhtColRelationDetail != null) {
                lhtColRelationDetail.clear();
                lhtColRelationDetail = null;
            }
        }
    }

    public void OutputDataView(DataViewForm actionForm,
                               PageContext pageContext) {
        try {
            String lstrHtmlCode = getOutputDataView(actionForm);
            if (lstrHtmlCode != null) {
                pageContext.getOut().println(lstrHtmlCode);
                pageContext.getOut().flush();
            }
        } catch (Exception e) {
            if (this.gblnDBDebug) {
                e.printStackTrace();
            }
            System.out.print(
                    "DataView.OutputDataView(actionForm,pageContext) Exception ==>");
            System.out.println(e.toString());
        } finally {

        }

    }

    private String outputPageControl(DataViewForm pdataViewForm,
                                     ArrayList<String> parylstCol) throws Exception {

        StringBuffer lstbHtmlCode = new StringBuffer();

        try {
            lstbHtmlCode.append("<tr>\r\n<td colspan='" +
                                String.valueOf(pdataViewForm.getColumnSize()) +
                                "'>\r\n");

            if (pdataViewForm.getAddNewShow()) { //產生動態新增的按鈕
                lstbHtmlCode.append("<input type='button' name='btnAddNew' value='Append Row' class='button b_normal' onclick='javascript:evt_dataview_btnAddNew_onclick();'/>\r\n");
                //lstbHtmlCode.append("<input type='button' name='btnAddNew' value='Append Row' class='button' onclick='javascript:fc_append_row();'/>\r\n");
                //lstbHtmlCode.append(this.getAppendRowHtml(pdataViewForm));
            }

            if (pdataViewForm.getBatchUpdateButtonShow()) { //產生批次存檔的按鈕
                lstbHtmlCode.append("<input type='button' name='btnBatchUpdate' value='Update' class='button b_normal' onclick='javascript:evt_dataview_btnBatchUpdate_onclick();'/>\r\n");
                //lstbHtmlCode.append(this.getAppendRowHtml(pdataViewForm));
            }
            if (pdataViewForm.getExitButtonShow()) { //產生window close的按鈕
                lstbHtmlCode.append("<input type='button' name='btnExit' value='Exit' class='button b_normal' onclick='javascript:evt_dataview_btnExit_onclick();'/>\r\n");
            }
            if (pdataViewForm.getTotalDataSize() == 0) {
                lstbHtmlCode.append("</td>\r\n</tr>\r\n");
                return lstbHtmlCode.toString();
            }

            if (pdataViewForm.getJumpPageButtonShow() &&
                pdataViewForm.getNowPageNum() > 1) { //產生上一頁的按鈕
                lstbHtmlCode.append(
                        "<input type=\"button\" name=\"btnPrivous\" value=\"Previous\" class='button b_normal' onclick=\"javascript:document.forms['" +
                        pdataViewForm.getHtmlFormName() +
                        "'].nowPageNum.value=" +
                        String.valueOf((pdataViewForm.getNowPageNum() - 1)) +
                        ";document.forms['" + pdataViewForm.getHtmlFormName() +
                        "'].dataViewAction.value='changePage';document.forms['" +
                        pdataViewForm.getHtmlFormName() + "'].submit();\">\r\n");
            }

            //產生下一頁的按鈕
            if (pdataViewForm.getJumpPageButtonShow() &&
                (pdataViewForm.getTotalDataSize() /
                 pdataViewForm.getPageRowCount()) + 1 !=
                pdataViewForm.getNowPageNum() &&
                pdataViewForm.getTotalDataSize() !=
                pdataViewForm.getPageRowCount()) {
                lstbHtmlCode.append(
                        "<input type=\"button\" name=\"btnNext\" value=\"Next\" class='button b_normal' onclick=\"javascript:document.forms['" +
                        pdataViewForm.getHtmlFormName() +
                        "'].nowPageNum.value=" +
                        String.valueOf((pdataViewForm.getNowPageNum() + 1)) +
                        ";document.forms['" + pdataViewForm.getHtmlFormName() +
                        "'].dataViewAction.value='changePage';document.forms['" +
                        pdataViewForm.getHtmlFormName() + "'].submit();\">\r\n");
            }

            //產生跳頁的選項
            if (pdataViewForm.getJumpPageShow() &&
                (pdataViewForm.getTotalDataSize() /
                 pdataViewForm.getPageRowCount()) + 1 != 1) {
                lstbHtmlCode.append(
                        "<select name=\"selPageNum\" " +
                        (!pdataViewForm.getJumpPageShow() ?
                         "style=\"display='none'\"" : "class='input'") +
                        " onchange=\"document.forms['" +
                        pdataViewForm.getHtmlFormName() +
                        "'].dataViewAction.value='changePage';document.forms['" +
                        pdataViewForm.getHtmlFormName() +
                        "'].nowPageNum.value=this.value;document.forms['" +
                        pdataViewForm.getHtmlFormName() + "'].submit();\">\r\n");
                for (int i = 1;
                             i <=
                             ((pdataViewForm.getTotalDataSize() - 1) /
                              pdataViewForm.getPageRowCount()) +
                             1; i++) {
                    lstbHtmlCode.append("<option value=" + i +
                                        (i == pdataViewForm.getNowPageNum() ?
                                         " selected " : "") + ">Page" + i +
                                        "</option>\r\n");
                }
                lstbHtmlCode.append("</select>\r\n");
            }

            //產生每頁筆數的設定欄位
            if (pdataViewForm.getRowPageShow()) {
                lstbHtmlCode.append("&nbsp;&nbsp;&nbsp;Row count of page");
                lstbHtmlCode.append(
                        "<input type=\"text\" name=\"pageRowCount\" size=\"3\" value=\"" +
                        pdataViewForm.getPageRowCount() +
                        "\" class='input' onchange=\"document.forms['" +
                        pdataViewForm.getHtmlFormName() +
                        "'].nowPageNum.selectedIndex=0;document.forms['" +
                        pdataViewForm.getHtmlFormName() +
                        "'].dataViewAction.value='changePage';document.forms['" +
                        pdataViewForm.getHtmlFormName() +
                        "'].submit();\"/>\r\n");
            }

            if (pdataViewForm.getFilterShow()) {
                outputFilter(pdataViewForm, parylstCol); //輸出過濾設定
            }

            if (pdataViewForm.getExcelShow()) { //show Excel button
                lstbHtmlCode.append(
                        "<input type=\"button\" name=\"btnCreateExcel\" value=\"Excel\" class='button b_normal' onclick=\"document.forms['" +
                        pdataViewForm.getHtmlFormName() +
                        "'].dataViewAction.value='excel';document.forms['" +
                        pdataViewForm.getHtmlFormName() + "'].submit();\">\r\n");
            }
            //lstbHtmlCode.append("</td>");

            //產生筆數資訊
            //lstbHtmlCode.append("<td valign='top'><div align=\"left\">");

            if (pdataViewForm.getRowsInfoShow()) {
                lstbHtmlCode.append("Page:" + pdataViewForm.getNowPageNum() +
                                    "/" +
                                    ((pdataViewForm.getTotalDataSize() /
                                      pdataViewForm.getPageRowCount()) +
                                     (pdataViewForm.getTotalDataSize() %
                                      pdataViewForm.getPageRowCount() == 0 ? 0 :
                                      1)));
                lstbHtmlCode.append(",Total Records:" +
                                    pdataViewForm.getTotalDataSize());
            }

            lstbHtmlCode.append("</td>\r\n");
            //lstbHtmlCode.append("</div></td>");

            lstbHtmlCode.append("</tr>\r\n");

            return lstbHtmlCode.toString();
            /*
                         pout.flush();
                         pout.clearBuffer();
                         pout = null;*/
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    private String outputLinkField(Hashtable<String,ArrayList<String>> phtColRelationDetail,
                                   int pintColNum, int pintRowNum) throws
            Exception {

        ArrayList<String> laltLinkParams = null;
        StringBuffer stbTargetURI = new StringBuffer();
        String strLinkURIValue = phtColRelationDetail.get(this.STR_LINK_URI).
                                 toString();
        String strFieldValue = phtColRelationDetail.get(this.STR_FIELD_VALUE).
                               toString();

        stbTargetURI.append((strLinkURIValue.indexOf("'") <
                             0 ?
                             ((Hashtable<String,Object>) ghtRowData.get(String.valueOf(
                                     pintRowNum))).get(
                                             strLinkURIValue).toString()
                             :
                             strLinkURIValue.replaceAll(
                                     "'",
                                     "")));

        try {
            if (phtColRelationDetail.get(this.STR_LINK_PARAM) != null) {

                //laltLinkParams = new ArrayList<Object>((ArrayList<String>) phtColRelationDetail.
                //                               get(this.
                //       STR_LINK_PARAM));
            	
            	laltLinkParams = (ArrayList<String>)phtColRelationDetail.get(this.STR_LINK_PARAM);
                for (int k = 0; k < laltLinkParams.size(); k++) {
                    if (k % 2 == 0) {
                        stbTargetURI.append(k == 0 ?
                                            (laltLinkParams.get(k).toString().
                                             equals("") ? "" : "?") : "&"); //若是第一個參數前用?連接，之後的參數以&連接
                        stbTargetURI.append(laltLinkParams.get(k).toString());
                    } else {
                        if (laltLinkParams.get(k).toString().indexOf("'") != 0) {
                            try {
                                stbTargetURI.append(((Hashtable<String,Object>) ghtRowData.get(
                                        String.valueOf(pintRowNum))).
                                        get(laltLinkParams.get(k).
                                            toString()).
                                        toString());
                            } catch (Exception se) {
                                throw new Exception("Link Fields,第" + pintRowNum + "筆取不到參數的值，請確認是否有select " + laltLinkParams.get(k).toString());
                            }
                        } else {
                            stbTargetURI.append(laltLinkParams.get(k).toString().replace('\'',' ').trim());
                        }
                    }
                }

            }

            //在鏈結位址(含參數)前後加單引號
            stbTargetURI.insert(0, "'");
            stbTargetURI.append("'");

            //將HTML tag輸出 ex.<a href=
            stbTargetURI.insert(0, phtColRelationDetail.get(this.
                    STR_FIELD_HTML).
                                toString()
                    );

            stbTargetURI.append(">");

            //輸出鏈結要顯示的值
            try {
                stbTargetURI.append((strFieldValue.
                                     indexOf(
                                             "'") !=
                                     -1 ?
                                     strFieldValue.
                                     replace(
                                             '\'',
                                             ' ') :
                                     ((Hashtable<String,Object>) ghtRowData.get(String.valueOf(
                                             pintRowNum))).get(
                        strFieldValue).toString()));
            } catch (Exception se) {
                throw new Exception("Link Fields,第" + pintRowNum +
                                    "筆,顯示值(<a href=''...>顯示值</a>)有問題,請確認有select " +
                                    strFieldValue + " 這個欄位" + se.toString());
            }
            stbTargetURI.append("</a>");

            if (gblnDBDebug) {
                System.out.println("stbTargetURI==>" + stbTargetURI.toString());
            }

            return stbTargetURI.toString().replaceAll(gstrReplaceRowSN,
                    String.valueOf(pintRowNum).trim());
        } catch (Exception e) {
            throw new Exception(e);
        } finally {
            if (stbTargetURI != null) {
                stbTargetURI.delete(0, stbTargetURI.length() - 1);
            }
            if (laltLinkParams != null) {
                laltLinkParams.clear();
                laltLinkParams = null;
            }
            stbTargetURI = null;
        }
    }

    /*
        private String outputSubmitField(int pintColNum, int pingRowNum) {
            StringBuffer lstbHtmlCode=new StringBuffer();
            Hashtable lhtColRelationDetail=null;

            try {
                lhtColRelationDetail=(Hashtable)ghtColRelation.get(galtColData.get(pintColNum).toString());

                lstbHtmlCode.append(lhtColRelationDetail.get(STR_FIELD_HTML).toString()); //輸出<form ....>
                lstbHtmlCode.append(lhtColRelationDetail.get(STR_FIELD_VALUE).toString()); //輸出<INPUT TYPE=SUBMIT .....>

     if (lhtColRelationDetail.get(STR_LINK_URI).toString().indexOf("'") != -1) { //輸出
     lstbHtmlCode.append(lhtColRelationDetail.get(STR_LINK_URI).toString());
                } else {
     lstbHtmlCode.append(((ArrayList) galtRowData.get(pingRowNum)).get(Integer.
                            parseInt(
     lhtColRelationDetail.get(STR_LINK_URI).toString())));
                }

                lstbHtmlCode.append("\" class='button'/>");

                for (int k = INT_PARAM_START_INDEX;
                             k <= gstrColRelation[pintColNum].length - 1;
                             k++) {
                    if (k % 2 == INT_PARAM_START_INDEX % 2) {
     if (gstrColRelation[pintColNum][k].indexOf("\"") != -1) {
     gout.print(gstrColRelation[pintColNum][k].toString().
                                       replaceAll(gstrReplaceRowSN,
     String.valueOf(pingRowNum).trim()));
                        }
                    } else {
     if (gstrColRelation[pintColNum][k].indexOf("'") == -1) {
     gout.print(((ArrayList) galtRowData.get(pingRowNum)).get(Integer.
                                    parseInt(gstrColRelation[pintColNum][k])));
                        } else {
     gout.print(gstrColRelation[pintColNum][k].replaceAll("'", " ").
                                       trim().
                                       replaceAll(gstrReplaceRowSN,
     String.valueOf(pingRowNum).trim()));
                        }
                        gout.println("\"/>");
                    }
                }
            } catch (Exception e) {
                System.out.println(e.toString() +
                                   " at OutputSubmitField in DataView.java");
            }
        }*/

    private String outputInputField(Hashtable<String,Object> phtColRelationDetail,
                                    int pintColNum, int pintRowNum) throws
            Exception {
        StringBuffer lstbHtmlCode = new StringBuffer();
        String lstrExceptionInformation = "";

        try {
            lstbHtmlCode.append(phtColRelationDetail.get(STR_FIELD_HTML).
                                toString().replaceAll(
                                        gstrReplaceRowSN,
                                        String.valueOf(pintRowNum).trim()));

            if (phtColRelationDetail.get(STR_FIELD_VALUE).toString().indexOf(
                    "'") != -1) {
                lstbHtmlCode.append("\"" +
                                    phtColRelationDetail.get(STR_FIELD_VALUE).
                                    toString().replace('\'',
                        ' ').
                                    trim().
                                    replaceAll(gstrReplaceRowSN,
                                               String.valueOf(pintRowNum).trim()) +
                                    "\"");
            } else {
                lstrExceptionInformation = "INPUT 對應不到SQL欄位:" +
                                           phtColRelationDetail.get(
                        STR_FIELD_VALUE).toString();

                lstbHtmlCode.append("\"" +
                                    ((Hashtable<String,Object>) ghtRowData.get(String.valueOf(
                                            pintRowNum))).
                                    get(phtColRelationDetail.get(
                                            STR_FIELD_VALUE).toString()).
                                    toString() +
                                    "\"");
            }
            lstbHtmlCode.append(" />");

            return lstbHtmlCode.toString();
        } catch (Exception e) {
            if (lstrExceptionInformation.equals("")) {
                throw new Exception(e);
            } else {
                throw new Exception(lstrExceptionInformation);
            }
        }
    }

    private String outputTextAreaField(Hashtable<String,String> phtColRelationDetail,
                                       int pintColNum, int pintRowNum) throws
            Exception {
        StringBuffer lstbHtmlCode = new StringBuffer();

        try {
            lstbHtmlCode.append(phtColRelationDetail.get(STR_FIELD_HTML).
                                toString().replaceAll(
                                        gstrReplaceRowSN,
                                        String.valueOf(pintRowNum).trim()));
            if (phtColRelationDetail.get(STR_FIELD_VALUE).toString().indexOf(
                    "'") != -1) {
                lstbHtmlCode.append(phtColRelationDetail.get(STR_FIELD_VALUE).
                                    toString().replace('\'',
                        ' ').
                                    trim().
                                    replaceAll(gstrReplaceRowSN,
                                               String.valueOf(pintRowNum).trim()));
            } else {
                lstbHtmlCode.append(((Hashtable<String,Object>) ghtRowData.get(String.valueOf(
                        pintRowNum))).
                                    get(phtColRelationDetail.get(
                                            STR_FIELD_VALUE).toString()).
                                    toString());
            }
            lstbHtmlCode.append("</textarea>");

            return lstbHtmlCode.toString();
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    private String outputSelectField(Hashtable<String,String> phtColRelationDetail,
                                     int pintColNum, int pintRowNum) throws
            Exception {
        String strSelectOptions[] = null;
        StringBuffer lstbHtmlCode = new StringBuffer();

        try {
            lstbHtmlCode.append(phtColRelationDetail.get(STR_FIELD_HTML).
                                toString().replaceAll(
                                        gstrReplaceRowSN,
                                        String.valueOf(pintRowNum).trim()));
            if (phtColRelationDetail.get(STR_FIELD_KIND).toString().length() >=
                8) { /*
                 strSelectOptions = gstrColRelation[pintColNum][Integer.parseInt(((
                                      ArrayList)
                 galtRowData.get(pintRowNum)).get(Integer.parseInt(
                        gstrColRelation[
                        pintColNum][
                 INT_FIELD_KIND].substring(0, 1))).toString()) +
                           Integer.
                 parseInt(gstrColRelation[pintColNum][INT_FIELD_KIND].
                                    substring(7))].
                           split(",");*/
             } else {
                 strSelectOptions = phtColRelationDetail.get(STR_FIELD_VALUE).
                                    toString().split(
                                            ",");

                 //if(gblnDebug)System.lstbHtmlCode.println("Field Kind length==>" + gstrColRelation[pintColNum][INT_FIELD_KIND].length());

             }
            for (int k = 0; k <= strSelectOptions.length - 1; k++) {
                if (strSelectOptions[k].substring(strSelectOptions[k].indexOf(
                        "\"") +
                                                  1,
                                                  strSelectOptions[k].indexOf(
                        "\"",
                        strSelectOptions[k].indexOf("\"") +
                        1)).equals(((Hashtable<String,Object>) ghtRowData.get(String.valueOf(
                                pintRowNum))).
                                   get(this.galtColData.get(pintColNum)).
                                   toString().
                                   trim())) {
                    lstbHtmlCode.append(strSelectOptions[k].substring(0,
                            7).replaceAll(gstrReplaceRowSN,
                                          String.valueOf(pintRowNum).trim()));
                    lstbHtmlCode.append(" selected ");
                    lstbHtmlCode.append(strSelectOptions[k].substring(8).
                                        replaceAll(
                                                gstrReplaceRowSN,
                                                String.valueOf(pintRowNum).trim()));
                } else {
                    lstbHtmlCode.append(strSelectOptions[k].replaceAll(
                            gstrReplaceRowSN,
                            String.valueOf(pintRowNum).trim()));
                }
            }

            return lstbHtmlCode.toString();
        } catch (Exception e) {
            throw new Exception(e);
        } finally {
            strSelectOptions = null;
        }
    }

    /**
     * outputDataTitle
     *
     * @param pblnNeedOrderBy ArrayList
     * @param pstrHtmlFormName String
     * @param pstrPropertiesFile String
     * @param pstrTableHeaderHtml String
     * @param parylstDataCol ArrayList
     * @throws Exception
     * @return String
     */
    private String outputDataTitle(boolean pblnNeedOrderBy,
                                   String pstrHtmlFormName,
                                   String pstrPropertiesFile,
                                   String pstrTableHeaderHtml,
                                   ArrayList<String> parylstDataCol) throws
            Exception {
        String lstrShowTitleName = null;
        StringBuffer lstbHtmlCode = new StringBuffer();
        Hashtable<String,Object> lhtColRelationDetail = null;

        try {
            lstbHtmlCode.append("<tr " + pstrTableHeaderHtml + " >\r\n");

            for (int lintColNum = 0; lintColNum < galtColData.size();
                                  lintColNum++) {
                lhtColRelationDetail = new Hashtable<String,Object>((Hashtable<String,Object>)
                        galtColRelation.
                        get(lintColNum));

                if (!lhtColRelationDetail.get(STR_FIELD_TITLE).toString().
                    equals("N") &&
                    !lhtColRelationDetail.get(STR_FIELD_TITLE).toString().
                    equals("HIDDEN")) { //判斷該欄是否要顯示
                    if (lhtColRelationDetail.get(STR_FIELD_TITLE).toString().
                        substring(0,
                                  1).equals("%")) { //若欄位名稱以%起始，則取出相對應的keyvalue
                        lstrShowTitleName = (new PropertyBean(
                                pstrPropertiesFile)).
                                            getString(lhtColRelationDetail.get(
                                STR_FIELD_TITLE).toString().substring(1));
                    } else if (lhtColRelationDetail.get(STR_FIELD_TITLE).
                               toString().substring(0, 1).
                               equals("'")) {
                        lstrShowTitleName = lhtColRelationDetail.get(
                                STR_FIELD_TITLE).toString().
                                            replaceAll(
                                "'",
                                "");
                    } else {
                        lstrShowTitleName = parylstDataCol.get(lintColNum).
                                            toString().toUpperCase();
                        //if(gblnDebug)System.lstbHtmlCode.append("title==>"+arylstCol.get(lintColNum).toString());
                    }

                    lstbHtmlCode.append("<td " +
                                        (pblnNeedOrderBy ?
                                         " onclick=\"if(document.forms['" +
                                         pstrHtmlFormName +
                                         "'].dvOrderByFields.value=='" +
                                         lstrShowTitleName +
                                         "'){if(document.forms['" +
                                         pstrHtmlFormName +
                                         "'].dvOrderBySeq.value=='asc'){document.forms['" +
                                         pstrHtmlFormName +
                                         "'].dvOrderBySeq.value='desc';}else{document.forms['" +
                                         pstrHtmlFormName +
                                         "'].dvOrderBySeq.value='asc';}}else{document.forms['" +
                                         pstrHtmlFormName +
                                         "'].dvOrderBySeq.value='asc';document.forms['" +
                                         pstrHtmlFormName +
                                         "'].dvOrderByFields.value='" +
                                         lstrShowTitleName +
                                         "'}document.forms['" +
                                         pstrHtmlFormName +
                                         "'].dataViewAction.value='sort';document.forms['" +
                                         pstrHtmlFormName + "'].submit();\"" :
                                         //"") + " valign='top' " +
                                         "") +
                                        lhtColRelationDetail.get(
                                                STR_FIELD_PROPERTY).toString() +
                                        " >");
                    lstbHtmlCode.append(lstrShowTitleName);
                    lstbHtmlCode.append("</td>\r\n");
                    if (lhtColRelationDetail.get(STR_FIELD_LINE_FEED) != null &&
                        Boolean.parseBoolean(lhtColRelationDetail.get(
                                STR_FIELD_LINE_FEED).toString())) {
                        lstbHtmlCode.append("\r\n");
                        lstbHtmlCode.append("</tr><tr ");
                        lstbHtmlCode.append(pstrTableHeaderHtml);
                        lstbHtmlCode.append(">");
                        lstbHtmlCode.append("\r\n");
                    }
                }
            }
            lstbHtmlCode.append("</tr>\r\n");

            return lstbHtmlCode.toString();
        } catch (Exception e) {
            throw new Exception(e);
        } finally {
            if (lhtColRelationDetail != null) {
                lhtColRelationDetail.clear();
                lhtColRelationDetail = null;
            }
        }
    }

    /**
     * outputFormHiddenFields
     *
     * @param pstrParams String[]
     * @param pdataViewForm DataViewForm
     * @throws Exception
     * @return String
     */
    private String outputFormHiddenFields(String[] pstrParams,
                                          DataViewForm pdataViewForm) throws
            Exception {
        StringBuffer lstbHtmlCode = new StringBuffer();
        int i = 0;
        try {
            for (i = 0; i <= pstrParams.length - 1; i++) {
                if (pstrParams[0].trim().equals("noparamters")) {
                    break;
                }

                lstbHtmlCode.append("<input type=\"hidden\" name=\"");
                lstbHtmlCode.append(pstrParams[i].substring(0,
                        pstrParams[i].indexOf("=")) +
                                    "\" value=\"");
                lstbHtmlCode.append(pstrParams[i].substring(pstrParams[i].
                        indexOf(
                                "=") +
                        1) + "\"/>\r\n");
            }
        } catch (Exception e) {
            throw new Exception("PageActionURI parameter error,第" + i +
                                "個參數錯誤,參數值為==>" + pstrParams[i]);
        }

        lstbHtmlCode.append(
                "<input type=\"hidden\" name=\"dataViewAction\" value=\"\">\r\n");
        lstbHtmlCode.append(
                "<input type=\"hidden\" name=\"nowPageNum\" value=\"" +
                pdataViewForm.getNowPageNum() + "\">\r\n");
        /*lstbHtmlCode.append("<input type=\"hidden\" name=\"pageRowCount\" value=\"" +
                     pdataViewForm.getPageRowCount() + "\"/>");*/
        lstbHtmlCode.append(
                "<input type=\"hidden\" name=\"dvSQLCondition\" value=\"" +
                (pdataViewForm.getdvSQLCondition() == null ? "" :
                 pdataViewForm.getdvSQLCondition()) + "\"/>\r\n");
        lstbHtmlCode.append(
                "<input type=\"hidden\" name=\"dvOrderByFields\" value=\"" +
                (pdataViewForm.getdvOrderByFields() == null ? "" :
                 pdataViewForm.getdvOrderByFields()) + "\"/>\r\n");
        lstbHtmlCode.append(
                "<input type=\"hidden\" name=\"dvOrderBySeq\" value=\"" +
                (pdataViewForm.getdvOrderBySeq() == null ? "" :
                 pdataViewForm.getdvOrderBySeq()) + "\"/>\r\n");
        lstbHtmlCode.append(
                "<input type=\"hidden\" name=\"changeRowNum\" value=\"\"/>\r\n");

        return lstbHtmlCode.toString();
    }

    /**
     * outputRowData
     *
     * @param pstrTableDataTrHtml String
     * @throws Exception
     * @return String
     */
    @SuppressWarnings("unchecked")
	private String outputRowData(String pstrTableDataTrHtml) throws Exception {
        String lstrFieldKind = null;
        Hashtable lhtColRelationDetail = null;
        StringBuffer lstbHtmlCode = new StringBuffer();

        try {
            for (int lintRowNum = 0; lintRowNum <= ghtRowData.size() - 1;
                                  lintRowNum++) {
                lstbHtmlCode.append("<tr " +
                                    (pstrTableDataTrHtml != null ?
                                     pstrTableDataTrHtml.
                                     replaceAll(gstrReplaceRowSN,
                                                String.valueOf(lintRowNum).trim()) :
                                     "") + ">\r\n");
                for (int lintColNum = 0; lintColNum < galtColRelation.size();
                                      lintColNum++) {
                    //取出欄位的設定集合
                    lhtColRelationDetail = new Hashtable<String,Object>((Hashtable<String,Object>)
                            galtColRelation.get(lintColNum));

                    if (lhtColRelationDetail == null) {
                        throw new Exception(
                                "lhtColRelationDetail is null in DataView.outputRowData(),lintRowNum==>" +
                                lintRowNum);
                    }

                    //這是判斷是否有寫動態改變欄位型的java code
                    //且第二維陣列至少要length>2 because aa[x][1]=field type
                    if ((lhtColRelationDetail.size() > this.INT_FIELD_KIND)) {
                        if (lhtColRelationDetail.get(STR_FIELD_KIND) != null &&
                            lhtColRelationDetail.get(STR_FIELD_KIND).toString().
                            indexOf("$") >=
                            0 &&
                            lhtColRelationDetail.get(STR_FIELD_KIND).toString().
                            indexOf("$",
                                    lhtColRelationDetail.get(STR_FIELD_KIND).
                                    toString().indexOf("$") + 1) >=
                            0) {
                            lstrFieldKind = evalDynamicCode(
                                    lhtColRelationDetail,
                                    (Hashtable<String,Object>) ghtRowData.get(String.valueOf(
                                            lintRowNum)));
                        } else {
                            // || lhtColRelationDetail.get(STR_FIELD_TITLE).toString().equals("HIDDEN")
                            if (lhtColRelationDetail.get(STR_FIELD_TITLE).
                                toString().equals("N")) {
                                lstrFieldKind = lhtColRelationDetail.get(
                                        STR_FIELD_TITLE).toString();
                            } else {
                                lstrFieldKind = lhtColRelationDetail.get(
                                        STR_FIELD_KIND).toString();
                            }
                        }
                    }

                    if (!lhtColRelationDetail.get(STR_FIELD_TITLE).toString().
                        equals("N")) {
                        if (!lhtColRelationDetail.get(STR_FIELD_TITLE).toString().
                            equals(
                                    "HIDDEN")) {
                            lstbHtmlCode.append(
                                    "<td " +
                                    (lhtColRelationDetail.get(
                                            STR_FIELD_PROPERTY).
                                     toString().
                                     toLowerCase().
                                     indexOf("class=") < 0 ?
                                     "class='td_content'" :
                                     "") +
                                    lhtColRelationDetail.get(STR_FIELD_PROPERTY).
                                    toString() +
                                    " >\r\n");
                        }
                        if (lstrFieldKind.equals(
                                "LINK")) { //判斷若參數值為其它欄位值時，
                            lstbHtmlCode.append(outputLinkField(
                                    lhtColRelationDetail, lintColNum,
                                    lintRowNum));
                        } else if (lstrFieldKind.
                                   equals("INPUT") ||
                                   lstrFieldKind.equals("SUBMIT")) {
                            lstbHtmlCode.append(outputInputField(
                                    lhtColRelationDetail, lintColNum,
                                    lintRowNum));
                        } else if (lstrFieldKind.
                                   equals(
                                           "TEXTAREA")) {
                            lstbHtmlCode.append(outputTextAreaField(
                                    lhtColRelationDetail, lintColNum,
                                    lintRowNum));
                        } else if (lstrFieldKind.
                                   equals(
                                           "IMG")) {
                            lstbHtmlCode.append(outputImageField(
                                    lhtColRelationDetail, lintColNum,
                                    lintRowNum)); ;
                        } else if (lstrFieldKind.
                                   equals(
                                           "RADIO")) {
                            lstbHtmlCode.append(outputRadioField(
                                    lhtColRelationDetail, lintColNum,
                                    lintRowNum)); ;
                        } else if (lstrFieldKind.
                                   toUpperCase().
                                   indexOf("SELECT") != -1) {
                            lstbHtmlCode.append(outputSelectField(
                                    lhtColRelationDetail, lintColNum,
                                    lintRowNum));
                        } else if (lstrFieldKind.
                                   equals("0")) {
                            lstbHtmlCode.append(((Hashtable) ghtRowData.get(
                                    String.valueOf(lintRowNum))).get(this.
                                    galtColData.get(lintColNum)).toString().
                                                equals("") ? "&nbsp;" :
                                                ((Hashtable) ghtRowData.get(
                                    String.valueOf(lintRowNum))).get(this.
                                    galtColData.get(lintColNum)).toString());
                            //若db撈出來的值為空字串,則回傳一個HTML的空白(&nbsp;),避免DataView在顯示時
                            //class='td_content' 會因為空字串而顯示不出來
                        }

                        lstbHtmlCode.append("\r\n");

                        if (!lhtColRelationDetail.get(STR_FIELD_TITLE).toString().
                            equals(
                                    "HIDDEN")) {
                            lstbHtmlCode.append("</td>\r\n");
                            if (lhtColRelationDetail.get(STR_FIELD_LINE_FEED) != null &&
                                Boolean.parseBoolean(lhtColRelationDetail.get(
                                        STR_FIELD_LINE_FEED).toString())) {
                                lstbHtmlCode.append("\r\n");
                                lstbHtmlCode.append("</tr><tr ");
                                lstbHtmlCode.append((pstrTableDataTrHtml != null ?
                                        pstrTableDataTrHtml.replaceAll(
                                                gstrReplaceRowSN,
                                                String.valueOf(lintRowNum).trim()) :
                                        ""));
                                lstbHtmlCode.append(">");
                                lstbHtmlCode.append("\r\n");
                            }
                        }
                    }
                }
                lstbHtmlCode.append("</tr>\r\n");
            }

            return lstbHtmlCode.toString();
        } catch (Exception e) {
            throw new Exception(e);
        } finally {
            if (lhtColRelationDetail != null) {
                lhtColRelationDetail.clear();
                lhtColRelationDetail = null;
            }
        }
    }

    /**
     * OutputRadioField
     *
     * @param phtColRelationDetail int
     * @param pintColNum int
     * @param pintRowNum int
     * @throws Exception
     * @return String
     */
    private String outputRadioField(Hashtable<String,Object> phtColRelationDetail,
                                    int pintColNum, int pintRowNum) throws
            Exception {
        //StringBuffer lstbHtmlCode = new StringBuffer();
        StringBuffer lstbFieldHtml = new StringBuffer();
        String lstrExceptionInformation = "";
        String strFieldValue = null;
        int iValuePos = 0;
        try {
            //轉換%sn%同時將value=轉換為大寫
            lstbFieldHtml.append(phtColRelationDetail.get(STR_FIELD_HTML).
                                 toString().replaceAll(
                                         gstrReplaceRowSN,
                                         String.valueOf(pintRowNum).trim()).
                                 replaceAll("value=", "VALUE="));

            lstrExceptionInformation = "INPUT cant find value:" +
                                       phtColRelationDetail.get(STR_FIELD_VALUE).
                                       toString();

            iValuePos = lstbFieldHtml.indexOf("VALUE=");
            if (iValuePos != -1) {
                strFieldValue = lstbFieldHtml.substring(iValuePos + 6);
                if (strFieldValue.substring(0, 1).equals("\"")) {
                    iValuePos = strFieldValue.indexOf("\"", 1);
                } else {
                    iValuePos = strFieldValue.indexOf("'", 1);
                }
                strFieldValue = strFieldValue.substring(1, iValuePos); //取value的值
            } else {
                throw new Exception(lstrExceptionInformation);
            }

            //固定字串
            if (phtColRelationDetail.get(STR_FIELD_VALUE).toString().indexOf(
                    "'") != -1) {
                //STR_FIELD_VALUE
                if (phtColRelationDetail.get(STR_FIELD_VALUE).toString().
                    replaceAll("'", "").equals(strFieldValue)) {
                    iValuePos = lstbFieldHtml.indexOf("VALUE=");
                    lstbFieldHtml.insert(iValuePos - 1, " CHECKED ");
                } //比對db值

            } else { //read db data
                lstrExceptionInformation = "INPUT 對應不到SQL欄位:" +
                                           phtColRelationDetail.get(
                        STR_FIELD_VALUE).toString();

                if (((Hashtable<String,Object>) ghtRowData.get(String.valueOf(
                        pintRowNum))).
                    get(phtColRelationDetail.get(
                            STR_FIELD_VALUE).toString())
                    .equals(strFieldValue)) {
                    iValuePos = lstbFieldHtml.indexOf("VALUE=");
                    lstbFieldHtml.insert(iValuePos - 1, " CHECKED ");
                } //比對db值

            } //else

            return lstbFieldHtml.toString();
        } catch (Exception e) {
            if (lstrExceptionInformation.equals("")) {
                throw new Exception(e);
            } else {
                throw new Exception(lstrExceptionInformation);
            }
        }
    }

    /**
     * OutputImageField
     *
     * @param phtColRelationDetail int
     * @param pintColNum int
     * @param pintRowNum int
     * @throws Exception
     * @return String
     */
    private String outputImageField(Hashtable<String,Object> phtColRelationDetail,
                                    int pintColNum, int pintRowNum) throws
            Exception {
        StringBuffer lstbHtmlCode = new StringBuffer();
        try {
            lstbHtmlCode.append(phtColRelationDetail.get(STR_FIELD_HTML).
                                toString().replaceAll(
                                        gstrReplaceRowSN,
                                        String.valueOf(pintRowNum).trim()));
            if (phtColRelationDetail.get(STR_FIELD_VALUE).toString().indexOf(
                    "'") != -1) {
                lstbHtmlCode.append(phtColRelationDetail.get(STR_FIELD_VALUE).
                                    toString().replace('\'',
                        ' ').
                                    trim().
                                    replaceAll(gstrReplaceRowSN,
                                               String.valueOf(pintRowNum).trim()));
            } else {
                lstbHtmlCode.append("'");
                lstbHtmlCode.append(((Hashtable<String,Object>) ghtRowData.get(String.valueOf(
                        pintRowNum))).
                                    get(phtColRelationDetail.get(
                                            STR_FIELD_VALUE).toString()).
                                    toString());
                lstbHtmlCode.append("'");
            }
            lstbHtmlCode.append("/>");

            return lstbHtmlCode.toString();
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    /**
     * evalDynamicCode
     *
     * @param phtColRelation String[]
     * @param phtData Hashtable
     * @throws Exception
     * @return String
     */
    private String evalDynamicCode(Hashtable<String,Object> phtColRelation,
                                   Hashtable<String,Object> phtData) throws Exception {
        Interpreter lbhsIPR = new Interpreter();
        String lstrEquation = null;

        try {
            lbhsIPR.set("phstData", phtData);
            lstrEquation = PublicFunction.replace(PublicFunction.replace(
                    phtColRelation.get(STR_FIELD_KIND).toString().substring(
                            phtColRelation.get(STR_FIELD_KIND).toString().
                            indexOf("$") +
                            1,
                            phtColRelation.get(STR_FIELD_KIND).toString().
                            indexOf("$",
                                    phtColRelation.get(STR_FIELD_KIND).toString().
                                    indexOf("$") + 1)).
                    replaceAll(
                            "&quot;", "\"").replaceAll("&&", "@and"), "{",
                    "phtData.get(", false), "}", ").toString()", false);

            return lbhsIPR.eval(lstrEquation).toString();
        } catch (Exception e) {
            throw new Exception(e);
        } finally {
            lbhsIPR = null;
        }
    }

    /**
     * outputFilter
     *
     * @param pdataViewForm DataViewForm
     * @param parylstCol ArrayList
     * @throws Exception
     * @return String
     */
    private String outputFilter(DataViewForm pdataViewForm,
                                ArrayList<String> parylstCol) throws
            Exception {
        StringBuffer lstbHtmlCode = new StringBuffer();
        Hashtable<String,Object> lhtColRelationDetail = null;

        try {
            lstbHtmlCode.append("&nbsp;&nbsp;&nbsp;Filter:");
            lstbHtmlCode.append("<select name='filterCol'>");
            for (int lintColNum = 0;
                                  lintColNum < pdataViewForm.getColumnSize();
                                  lintColNum++) {
                lhtColRelationDetail = new Hashtable<String,Object>((Hashtable<String,Object>)
                        galtColRelation.
                        get(lintColNum));

                if (!lhtColRelationDetail.get(STR_FIELD_TITLE).toString().
                    equals("N") &&
                    !lhtColRelationDetail.get(STR_FIELD_TITLE).toString().
                    equals("HIDDEN")) { //判斷該欄是否要顯示
                    lstbHtmlCode.append("<option>");
                    if (lhtColRelationDetail.get(STR_FIELD_TITLE).toString().
                        substring(0,
                                  1).equals("%")) { //若欄位名稱以%起始，則取出相對應的keyvalue
                        lstbHtmlCode.append((new PropertyBean(pdataViewForm.
                                getPropertiesFile())).
                                            getString(lhtColRelationDetail.get(
                                STR_FIELD_TITLE).toString().substring(1)));
                    } else if (lhtColRelationDetail.get(STR_FIELD_TITLE).
                               toString().substring(0, 1).
                               equals("'")) {
                        lstbHtmlCode.append(lhtColRelationDetail.get(
                                STR_FIELD_TITLE).toString().
                                            replaceAll(
                                "'",
                                ""));
                    } else {
                        lstbHtmlCode.append(parylstCol.get(lintColNum).toString().
                                            toUpperCase());
                    }
                    lstbHtmlCode.append("</option>");
                }
            }
            lstbHtmlCode.append("</select>");

            lstbHtmlCode.append(
                    "<input type='text' name='filterValue' size='20'>");

            lstbHtmlCode.append(
                    "<input type='button' name='btnFilter' value='Filter' onclick=\"document.forms['" +
                    pdataViewForm.getHtmlFormName() +
                    "'].dataViewAction.value='filter';document.forms['" +
                    pdataViewForm.getHtmlFormName() + "'].submit();\">");

            return lstbHtmlCode.toString();
        } catch (Exception e) {
            throw new Exception(e);
        } finally {
            if (lhtColRelationDetail != null) {
                lhtColRelationDetail.clear();
                lhtColRelationDetail = null;
            }
        }
    }

    private String combindSQL(String pstrFieldsList, String pstrTablesList,
                              String pstrSQLCondition, String pstrOrderByFields,
                              String pstrOrderBySeq, String pstrGroupBy,
                              String pstrHaving) {
        StringBuffer stbSQL = new StringBuffer();

        stbSQL.append("select ");
        stbSQL.append(pstrFieldsList);
        stbSQL.append(" from ");
        stbSQL.append(pstrTablesList);
        stbSQL.append(pstrSQLCondition != null &&
                      !
                      pstrSQLCondition.trim().equals(
                              "") ?
                      " where " + pstrSQLCondition :
                      "");
        stbSQL.append(pstrGroupBy != null &&
                      !pstrGroupBy.trim().equals("") ?
                      " group by " + pstrGroupBy : "");
        stbSQL.append(pstrHaving != null &&
                      !pstrHaving.trim().equals("") ?
                      " having " + pstrHaving : "");
        stbSQL.append(pstrOrderByFields != null &&
                      !pstrOrderByFields.trim().
                      equals("") ?
                      " order by " + pstrOrderByFields +
                      " " : "");
        stbSQL.append(pstrOrderBySeq != null &&
                      !
                      pstrOrderBySeq.trim().equals("") ?
                      pstrOrderBySeq : "");
        return stbSQL.toString();
    }

    private String combindSelectFields(ArrayList<Hashtable<String,Object>> paltColRelation) throws
            Exception {
        StringBuffer stbSQL = new StringBuffer();

        try {
            for (int i = 0; i < paltColRelation.size(); i++) {
                if (((Hashtable<String,Object>) paltColRelation.get(i)).get(STR_FIELD_SUB_SQL) != null &&
                    !((Hashtable<String,Object>) paltColRelation.get(i)).get(STR_FIELD_SUB_SQL).
                    toString().trim().equals("")) {
                    stbSQL.append(((Hashtable<String,Object>) paltColRelation.get(i)).get(
                            STR_FIELD_SUB_SQL).toString().trim());
                    stbSQL.append(" as ");
                    stbSQL.append(((Hashtable<String,Object>) paltColRelation.get(i)).get(
                            STR_FIELD_NAME).toString().trim());
                } else {
                    stbSQL.append(((Hashtable<String,Object>) paltColRelation.get(i)).get(
                            STR_FIELD_NAME).toString().trim());
                }
                if (i != paltColRelation.size() - 1) {
                    stbSQL.append(",");
                }
            }
            return stbSQL.toString();
        } catch (Exception e) {
            throw new Exception(e);
        }
    }

    private String combindCountSQL(DataViewForm dataViewForm) {
        return dataViewForm.getCountSQL() == null ||
                dataViewForm.getCountSQL().trim().
                equals("") ?
                (
                        combindSQL(dataViewForm.
                                   getPrimaryField() == null ||
                                   dataViewForm.getPrimaryField().trim().
                                   equals("") ?
                                   "count(*)" :
                                   "count(" + dataViewForm.getPrimaryField() +
                                   ")",
                                   dataViewForm.getTablesList(),
                                   dataViewForm.getSQLCondition(),
                                   "", "", /*count 時使用ORDER BY 語法在access有問題*/
                                   dataViewForm.getGroupBy(),
                                   dataViewForm.getHaving())) :
                dataViewForm.getCountSQL();

    }

    /*
        private void setFieldContent(String[] pstrColRelation){
            if(galtLinkURIParamContent!=null){galtLinkURIParamContent.clear();}

            gstrFieldTitleContent=pstrColRelation[this.INT_FIELD_TITLE];
            gstrFieldDataContent=pstrColRelation[this.INT_FIELD_DATA];
            gstrFieldTypeContent=pstrColRelation[this.INT_FIELD_TYPE];
            gstrFieldKindContent=pstrColRelation[this.INT_FIELD_KIND];
            gstrFieldPropertyContent=pstrColRelation[this.INT_FIELD_PROPERTY];
            gstrFieldHtmlContent=pstrColRelation[this.INT_FIELD_HTML];
            gstrFieldValueContent=pstrColRelation[this.INT_FIELD_VALUE];
            gstrLinkURIContent=pstrColRelation[this.INT_LINK_URI];

            if(gstrFieldKindContent.equals("LINK")){
     for(int i=this.INT_PARAM_START_INDEX;i<pstrColRelation.length;i++){
                    galtLinkURIParamContent.add(pstrColRelation[i]);
                }
            }
        }

        private void setFieldContent(Hashtable phtColRelation){
     gstrFieldTitleContent=phtColRelation.get(this.STR_FIELD_TITLE).toString();
     gstrFieldDataContent=phtColRelation.get(this.STR_FIELD_DATA).toString();
     gstrFieldTypeContent=phtColRelation.get(this.STR_FIELD_TYPE).toString();
     gstrFieldKindContent=phtColRelation.get(this.STR_FIELD_KIND).toString();
     gstrFieldPropertyContent=phtColRelation.get(this.STR_FIELD_PROPERTY).toString();
     gstrFieldHtmlContent=phtColRelation.get(this.STR_FIELD_HTML).toString();
     gstrFieldValueContent=phtColRelation.get(this.STR_FIELD_VALUE).toString();
     gstrLinkURIContent=phtColRelation.get(this.STR_LINK_URI).toString();

            if(gstrFieldKindContent.equals("LINK")){
     galtLinkURIParamContent=(ArrayList)phtColRelation.get(this.STR_PARAM_PREFIX);
            }
        }*/

    /**
     * transferStringArrayColRelationToHastable
     *
     * @param pstrColRelation String[][]
     * @param paltColData String
     * @return Hashtable
     * @throws Exception
     */
    private ArrayList<Hashtable<String,Object>> transferStringArrayColRelationToArrayList(String[][]
            pstrColRelation, ArrayList<String> paltColData) throws Exception {

        //Hashtable lhtColRelation = new Hashtable();
        ArrayList<Hashtable<String,Object>> laltColRelation = new ArrayList<Hashtable<String,Object>>();
        Hashtable<String,Object> lhtColRelationDetail = new Hashtable<String,Object>();
        ArrayList<String> laltLinkURIParamContent = new ArrayList<String>();
        String[] lstrColRelationDetail = null;
        //String[] lstrFieldName=null;

        try {
            /*if (pstrColRelation.length != paltColData.size()) {
                throw new Exception("字串陣列大小與SQL欄位個數不符合");
                         }*/

            for (int i = 0; i < pstrColRelation.length; i++) {
                lstrColRelationDetail = pstrColRelation[i];
                //lhtColRelationDetail.put(STR_FIELD_SEQNO,String.valueOf(i));

                if (lstrColRelationDetail.length > 0 &&
                    lstrColRelationDetail[INT_FIELD_TITLE] != null) {
                    lhtColRelationDetail.put(STR_FIELD_TITLE,
                                             lstrColRelationDetail[
                                             INT_FIELD_TITLE]);
                }
                if (lstrColRelationDetail.length > 1 &&
                    lstrColRelationDetail[INT_FIELD_KIND] != null) {
                    lhtColRelationDetail.put(STR_FIELD_KIND,
                                             lstrColRelationDetail[
                                             INT_FIELD_KIND]);
                }
                if (lstrColRelationDetail.length > 2 &&
                    lstrColRelationDetail[INT_FIELD_PROPERTY] != null) {
                    lhtColRelationDetail.put(STR_FIELD_PROPERTY,
                                             lstrColRelationDetail[
                                             INT_FIELD_PROPERTY]);
                }
                if (lstrColRelationDetail.length > 3 &&
                    lstrColRelationDetail[INT_FIELD_HTML] != null) {
                    lhtColRelationDetail.put(STR_FIELD_HTML,
                                             lstrColRelationDetail[
                                             INT_FIELD_HTML]);
                }
                if (lstrColRelationDetail.length > 4 &&
                    lstrColRelationDetail[INT_FIELD_VALUE] != null) {
                    if (lstrColRelationDetail[INT_FIELD_VALUE].indexOf("'") >=
                        0) {
                        lhtColRelationDetail.put(STR_FIELD_VALUE,
                                                 lstrColRelationDetail[
                                                 INT_FIELD_VALUE]);
                    } else {
                        if (Character.isDigit(lstrColRelationDetail[
                                              INT_FIELD_VALUE].charAt(0))) { //判斷第一個字是否是數字
                            lhtColRelationDetail.put(STR_FIELD_VALUE,
                                    paltColData.get(Integer.parseInt(
                                            lstrColRelationDetail[
                                            INT_FIELD_VALUE])).
                                    toString().toUpperCase());
                        } else {
                            lhtColRelationDetail.put(STR_FIELD_VALUE,
                                    lstrColRelationDetail[INT_FIELD_VALUE]);
                        }
                    }
                }

                if (lstrColRelationDetail.length > 5 &&
                    lstrColRelationDetail[INT_LINK_URI] != null) {
                    if (lstrColRelationDetail[INT_LINK_URI].indexOf("'") >= 0) {
                        lhtColRelationDetail.put(STR_LINK_URI,
                                                 lstrColRelationDetail[
                                                 INT_LINK_URI]);
                    } else {
                        if (Character.isDigit(lstrColRelationDetail[
                                              INT_LINK_URI].charAt(0))) { //判斷第一個字是否是數字
                            lhtColRelationDetail.put(STR_LINK_URI,
                                    paltColData.
                                    get(Integer.parseInt(lstrColRelationDetail[
                                    INT_LINK_URI])).toString().toUpperCase());
                        } else {
                            lhtColRelationDetail.put(STR_LINK_URI,
                                    lstrColRelationDetail[INT_LINK_URI]);
                        }
                    }
                }

                if (!lstrColRelationDetail[this.INT_FIELD_TITLE].equals("N") &&
                    (lstrColRelationDetail[this.INT_FIELD_KIND] != null &&
                     lstrColRelationDetail[this.INT_FIELD_KIND].equals("LINK"))) {
                    for (int j = this.INT_PARAM_START_INDEX;
                                 j < lstrColRelationDetail.length; j++) {
                        if (j % 2 != this.INT_PARAM_START_INDEX % 2) { //參數值
                            if (lstrColRelationDetail[j].indexOf("'") >= 0) {
                                laltLinkURIParamContent.add(
                                        lstrColRelationDetail[j]);
                            } else {
                                if (Character.isDigit(lstrColRelationDetail[j].
                                        charAt(0))) { //判斷第一個字是否是數字
                                    laltLinkURIParamContent.add(paltColData.get(
                                            Integer.parseInt(
                                            lstrColRelationDetail[j])).toString().
                                            toUpperCase());
                                } else {
                                    laltLinkURIParamContent.add(
                                            lstrColRelationDetail[j]);
                                }
                            }
                        } else {
                            laltLinkURIParamContent.add(lstrColRelationDetail[j]); //參數名稱
                        }
                    }
                    lhtColRelationDetail.put(STR_LINK_PARAM,
                                             new ArrayList<String>(
                            laltLinkURIParamContent));
                }

                laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
                lhtColRelationDetail.clear();
                laltLinkURIParamContent.clear();
            }
            return laltColRelation;
        } catch (Exception e) {
            if (gblnDBDebug) {
                e.printStackTrace();
            }
            throw new Exception(e);
        } finally {
            lhtColRelationDetail.clear();
            laltLinkURIParamContent.clear();
            lhtColRelationDetail = null;
            laltLinkURIParamContent = null;
            lstrColRelationDetail = null;
        }
    }

    /**
     * getAppendRowHtml
     *
     * @param pdataViewForm DataViewForm
     * @return String
     * @throws Exception
     */
    public String getAppendRowHtml(DataViewForm pdataViewForm,
                                   ArrayList<Hashtable<String,Object>> paltColRelation) throws
            Exception {
        StringBuffer lstbHtmlCode = new StringBuffer();
        Hashtable<String,Object> lhtColRelationDetail = null;
        //int lintTdNum = 0;
        String lstrFieldKind = "";
        String lstrFieldAppendRowHtml = "";
        int lintRowNum = 1;
        String[] lstrFldAttribute = null;
        //String[] lstrFldEveryAttribute = null;
        int lintNewLineCount = 0;


        //設定動態新增的Javascript
        //lstbHtmlCode.append("<input type='button' name='btnAddNew' value='Append Row' class='button' onclick='javascript:fc_append_row();'/>");
        lstbHtmlCode.append(
                "\r\n<script lang='java' language='javascript'>\r\nwindow.eval(\"window.evt_dataview_btnAddNew_onclick=function(){");
        lstbHtmlCode.append("var newTd=new Array(");
        lstbHtmlCode.append(pdataViewForm.getColumnSize());
        lstbHtmlCode.append(");");

        for (int lintColNum = 0; lintColNum < paltColRelation.size();
                              lintColNum++) {

            //判斷是要否要換行
            if (lintColNum == 0 ||
                (lhtColRelationDetail.get(STR_FIELD_LINE_FEED) != null &&
                 Boolean.parseBoolean(lhtColRelationDetail.get(
                         STR_FIELD_LINE_FEED).toString()))) {

                if (lintColNum == 0) {
                    lstbHtmlCode.append("document.");
                    lstbHtmlCode.append(pdataViewForm.getHtmlFormName());
                    lstbHtmlCode.append(".changeRowNum.value=document.");
                    lstbHtmlCode.append(pdataViewForm.getHtmlFormName());
                    lstbHtmlCode.append(".changeRowNum.value + (document.");
                    lstbHtmlCode.append(pdataViewForm.getHtmlFormName());
                    lstbHtmlCode.append(".changeRowNum.value=='' ? '' : ',') +");
                    lstbHtmlCode.append(pdataViewForm.getTableId());
                    lstbHtmlCode.append("Body");
                    lstbHtmlCode.append(".rows.length/lintNewLineCount;");
                }
                lstbHtmlCode.append("var newTr" + lintRowNum + "=");
                lstbHtmlCode.append(pdataViewForm.getTableId());
                lstbHtmlCode.append("Body");
                lstbHtmlCode.append(".insertRow(");
                lstbHtmlCode.append(pdataViewForm.getTableId());
                lstbHtmlCode.append("Body");
                lstbHtmlCode.append(".rows.length");
                lstbHtmlCode.append(");");
                lintRowNum++;
                lintNewLineCount++;//用來記錄一筆record的行數
            }

            //取出欄位的設定集合
            lhtColRelationDetail = new Hashtable<String,Object>((Hashtable<String,Object>)
                                                 paltColRelation.get(lintColNum));

            if (lhtColRelationDetail == null) {
                throw new Exception(
                        "lhtColRelationDetail is null in DataView.getAppendRowHtml(),lintColNum==>" +
                        lintColNum);
            }

            lstrFieldKind = lhtColRelationDetail.get(lhtColRelationDetail.get(
                    STR_FIELD_TITLE).toString().equals("N") ? STR_FIELD_TITLE :
                    STR_FIELD_KIND).toString();
            lstrFieldAppendRowHtml = lhtColRelationDetail.get(this.
                    STR_FIELD_APPEND_ROW_HTML) == null ? "" :
                                     lhtColRelationDetail.get(this.
                    STR_FIELD_APPEND_ROW_HTML).toString();

            lstbHtmlCode.append("newTd[");
            lstbHtmlCode.append(lintColNum);
            lstbHtmlCode.append("]=newTr" + String.valueOf(lintRowNum - 1) +
                                ".insertCell();");
            lstbHtmlCode.append("newTd[");
            lstbHtmlCode.append(lintColNum);
            lstbHtmlCode.append("].className='td_content';");
            lstbHtmlCode.append("newTd[");
            lstbHtmlCode.append(lintColNum);
            //lstbHtmlCode.append("].innerHTML=&quot;");
            lstbHtmlCode.append("].innerHTML=\\\"");

            //若原本欄位就是設定不顯示或隱藏，不管有沒有指定新增HTML都不顯示(會影響欄位編排)
            if (!lstrFieldKind.equals("N") && !lstrFieldKind.equals("HIDDEN")) {
                lstbHtmlCode.append(lstrFieldAppendRowHtml);
            }

            //lstbHtmlCode.append("&quot;;");
            lstbHtmlCode.append("\\\";");

            //設定fld attribute
            lstrFldAttribute = lhtColRelationDetail.get(this.STR_FIELD_PROPERTY).
                               toString().split(" ");

            for (int i = 0; i < lstrFldAttribute.length; i++) {
                lstbHtmlCode.append("newTd[");
                lstbHtmlCode.append(lintColNum);
                lstbHtmlCode.append("].setAttribute('");
                lstbHtmlCode.append(lstrFldAttribute[i].split("=")[0]);
                //lstbHtmlCode.append("',&quot;");
                lstbHtmlCode.append("','");
                lstbHtmlCode.append(lstrFldAttribute[i].split("=")[1].
                                    replaceAll("'", "").replaceAll("\"", ""));
                //lstbHtmlCode.append("&quot;);");
                lstbHtmlCode.append("');");
            }
        }
        lstbHtmlCode.append("}\");");
        lstbHtmlCode.append("</script>");
        if(lintNewLineCount>1){
            //若一筆記錄用多行來顯示，其seqno必須除於行的倍數
            lstbHtmlCode.replace(lstbHtmlCode.indexOf("lintNewLineCount"),
                                 lstbHtmlCode.indexOf("lintNewLineCount") +
                                 "lintNewLineCount".length(),
                                 String.valueOf(lintNewLineCount));
        }else if(lintNewLineCount==1){
            lstbHtmlCode.delete(lstbHtmlCode.indexOf("/lintNewLineCount"),lstbHtmlCode.indexOf("/lintNewLineCount") +
                                             "/lintNewLineCount".length());
        }
        return lstbHtmlCode.toString();
    }
}
